//引入Vue核心库
import Vue from 'vue'
//引入Vuex
import Vuex from 'vuex'
import axios from 'axios'
//应用Vuex插件
Vue.use(Vuex)

//准备actions对象——响应组件中的动作
const actions = {
  getReferencePoints(context) {
    axios.get('/api2/collector/getRps').then(
      (response) => {
        console.log(response)
        context.commit('GET_RPS', response.data.data)
      },
      (error) => {
        console.log(error.message)
      }
    )
  },
  getDevices(context){
    axios.get('/api1/location/getDevices').then(
        (response) => {
          console.log(response)
          context.commit('GET_DEVICES', response.data.data)
        },
        (error) => {
          console.log(error.message)
        }
      )
  }
}
//准备mutations对象——操作state中的数据
const mutations = {
  GET_RPS(state, value) {
    state.referencePoints = value
  },
  GET_DEVICES(state, value) {
    state.devices = value
  },
}
//准备state对象——存储具体的数据
const state = {
  referencePoints: [],
  devices: [],
}

const getters = {}

//创建并暴露store
export default new Vuex.Store({
  actions,
  mutations,
  state,
  getters,
})
